package com.yehongyu.mytools.ui.app;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MainFrame() throws HeadlessException {
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;

		// set frame size and location
		setSize(screenWidth / 2, screenHeight / 2);
		setLocation(screenWidth / 4, screenHeight / 4);

		// set img sign the application
		Image img = kit
				.getImage("D:\\application\\src\\com\\sinosoft\\yehy\\logo.gif");
		setIconImage(img);

		// set title sign the application
		setTitle("My first window application@today!");

		// setExtendedState(Frame.MAXIMIZED_BOTH); // set frame max
		setResizable(true); // set frame resizable

		// end the course when click the close,this is very importance
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		// add contentPane to frame
		Container contentPane = getContentPane();
//		contentPane.setLayout(new GridLayout(2, 2)); //网格布局
//		contentPane.setLayout(new FlowLayout()); //流布局
		contentPane.setLayout(new BorderLayout()); //（默认）边界布局
//		contentPane.setLayout(new GridBagLayout()); //无序网格布局

		// add panel to contentPane
		MyPanel mypanel = new MyPanel();
		mypanel.setBackground(SystemColor.control);
		

		// ButtonApplet buttonApplet = new ButtonApplet();
		// contentPane.add(buttonApplet);

		// contentPane.add(showBorder(new TitledBorder("Title")));

		ListOne list1 = new ListOne();
		ListTwo list2 = new ListTwo();
		ListThree list3 = new ListThree();
		ListFour list4 = new ListFour();
		SaveButton saveButton = new SaveButton(list1, list2);
		DelButton delButton = new DelButton(list1, list2);
		mypanel.add(list1);
		mypanel.add(list2);
		mypanel.add(list3);
		mypanel.add(list4);
		mypanel.add(saveButton, BorderLayout.WEST);
		mypanel.add(delButton, BorderLayout.WEST);

		contentPane.add(mypanel, BorderLayout.CENTER);

		// TextField t = new TextField("Starting text", 30);
		// contentPane.add(t);
		
//		RepaintManager.currentManager(this.getRootPane()).setDoubleBufferingEnabled(false);
//		((JComponent)this.getContentPane()).setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);
//		((JComponent)this.getContentPane()).setDebugGraphicsOptions(DebugGraphics.flashTime());
	}

	static JPanel showBorder(Border b) {
		JPanel jp = new JPanel();
		jp.setLayout(new BorderLayout());
		String nm = b.getClass().toString();
		nm = nm.substring(nm.lastIndexOf('.') + 1);
		jp.add(new JLabel(nm, JLabel.CENTER), BorderLayout.CENTER);
		jp.setBorder(b);
		return jp;
	}

	public MainFrame(GraphicsConfiguration gc) {
		super(gc);
		// TODO Auto-generated constructor stub
	}

	public MainFrame(String title) throws HeadlessException {
		super(title);
		// TODO Auto-generated constructor stub
	}

	public MainFrame(String title, GraphicsConfiguration gc) {
		super(title, gc);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
